<?php
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | 这里是针对反馈表单的一些处理
// +----------------------------------------------------------------------
// | Author: 邓继松
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\AuthController;

class FeedbackController extends AuthController {
    protected function _initialize(){
		parent::_initialize();
        $sys=M('options')->where(array('option_name'=>'site_options'))->getField("option_value");
        $sys=json_decode($sys,true);
		$arr=list_file(APP_PATH.'Home/View/'.$sys['site_tpl'],'*.html');
		$tpls=array();
		foreach($arr as $v){
			$tpls[]=basename($v['filename'],'.html');
		}
		$this->tpls=$tpls;
    }
	//文章列表,带搜索
	public function index(){
		$map = array();
		$keytype=I('keytype','mobile');
		$key=I('post.key');
	
		//查询：时间格式过滤
		$sldate=I('ctime','');//获取格式 2015-11-12 - 2015-11-18
		$arr = explode(" - ",$sldate);//转换成数组
        if(count($arr)==2){
            $arrdateone=strtotime($arr[0]);
            $arrdatetwo=strtotime($arr[1].' 23:55:55');
            $map['ctime'] = array(array('egt',$arrdateone),array('elt',$arrdatetwo),'AND');
        }
		
		if($keytype=='mobile'){
            $map[$keytype]= array('like',"%".$key."%");
        }else{
            $map[$keytype]= $key;
        }
		
		$n_id = I('id');
		$map['forms_id']= $n_id ;
        $rs=M('forms_value');
		$count= $rs->where($map)->count();// 查询满足要求的总记录数
		$Page= new \Think\Page($count,C('DB_PAGENUM'));// 实例化分页类 传入总记录数和每页显示的记录数
		$show= $Page->show();// 分页显示输出
		$this->assign('page',$show);
		$listRows=(intval(C('DB_PAGENUM'))>0)?C('DB_PAGENUM'):20;
		if($count>$listRows){
			$Page->setConfig('theme','<div class=pagination><ul> %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% %end%</ul></div>');
		}
		$show= $Page->show();// 分页显示输出
		$this->assign('page_min',$show);
		$news=$rs->where($map)->limit($Page->firstRow.','.$Page->listRows)->order('cTime desc')->select();
		
		
		$new = M ( 'news' )->field('n_id,news_title')  -> where ( array('n_id'=> $n_id) )->find();
		$this->assign('new',$new);
		/**
		//动态加表头，每个表头不同
		$dao = M ('forms_attribute');
		$fields = $dao -> where ( $map) -> order ( 'sort asc, id asc' )-> select();
		$tabhb = array();
		foreach ($fields as $key => $value) {
				$tabhb[$key]['title'] = $value['title'] ;
		}
		$this->assign('tabhb',$tabhb);    //动态表头
		 * 
		 * 
		 */
		
		foreach ($news as $k => $value) {
			$news[$k]["value"] = unserialize($value["value"]);
			$news[$k]["wotab"] = implode(';',$news[$k]["value"]);   //又转成文本了
			unset($news[$k]["value"]);
		}
		$this->assign('keytype',$keytype);   //搜索类型
		$this->assign('keyy',$key);          //搜索内容
		$this->assign('sldate',$sldate);     //时间段
		$this->assign('list',$news);
		$this->display();
	}

	//审核反馈
	public function news_state(){
		$id=I('x');
		$status=M('forms_value')->where(array('id'=>$id))->getField('isshow');//判断当前状态情况
		if($status==1){
			$statedata = array('isshow'=>0);
			$auth_group=M('forms_value')->where(array('id'=>$id))->setField($statedata);
			$this->success('未处理',1,1);
		}else{
			$statedata = array('isshow'=>1);
			$auth_group=M('forms_value')->where(array('id'=>$id))->setField($statedata);
			$this->success('已处理',1,1);
		}
	}
	
	//批量审核
	public function news_alldel(){
		$p = I('p');
		$ids = I('n_id');
		if(empty($ids)){
			$this -> error("请选择处理客户",U('news_list',array('p'=>$p)),0);//判断是否选择了文章ID
		}
		if(is_array($ids)){//判断获取文章ID的形式是否数组
			$where = 'id in('.implode(',',$ids).')';
		}else{
			$where = 'id='.$ids;
		}
		M('forms_value')->where($where)->setField('isshow',1);//转入回收站
		$this->success("已处理");
	}
	
	//批量删除
	public function alldel(){
		$p = I('p');
		$ids = I('n_id');
		if(empty($ids)){
			$this -> error("请选择处理客户",U('news_list',array('p'=>$p)),0);//判断是否选择了文章ID
		}
		if(is_array($ids)){//判断获取文章ID的形式是否数组
			$where = 'id in('.implode(',',$ids).')';
		}else{
			$where = 'id='.$ids;
		}
		M('forms_value')->where($where)->delete() ;     //直接删除
		$this->success("已删除");
	}
	
	
	
	
	
	

	//批量导出数据
	public function export(){
		
		
		$this->show('时间紧任务重，这个以后根据需要再搞');
		
		
		
	}
	
	//复制
	public function cope(){
		
		
		$this->show('时间紧任务重，这个以后根据需要再搞');
		
		
		
	}

















}